package com.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Slf4j
@Controller
@RequestMapping("/priority")
public class PriorityController {
    private RabbitTemplate rabbitTemplate;

    public PriorityController(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }

    @GetMapping("/{message}")
    public void test(@PathVariable("message") String message) {
        //参数输入String-Integer
        String[] split = message.split("-");
        rabbitTemplate.convertAndSend("priority.exchange", "", split[0], msg -> {
            msg.getMessageProperties().setPriority(Integer.parseInt(split[1]));
            return msg;
        });
        log.info("发送消息内容为{}", message);
    }
}
